import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserModule } from './feature/user/user.module';
import { AuthModule } from './core/auth/auth.module';
import { PostModule } from './feature/post/post.module';
import { User } from './entities/user.entity';
import { Post } from './entities/post.entity';
import { JwtModule } from '@nestjs/jwt';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql', // 连接mysql数据库
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'nest',
      autoLoadEntities: true,
      entities: [User, Post],
      synchronize: true, // 自动同步实体到数据库
    }),
    JwtModule.register({
      secret: 'your-secret-key', // 在实际应用中应使用环境变量
      signOptions: { expiresIn: '30d' },
      global: true, // 全局注册JwtModule
    }),
    UserModule,
    AuthModule,
    PostModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
